@echo off
echo "==>TAO_ROOT=%TAO_ROOT%"
echo "==>ACE_ROOT=%ACE_ROOT%"

set PROJECT_PATH="%TAO_ROOT%/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC"
cd %PROJECT_PATH%


@echo off
setlocal

:: 定义要删除的文件列表 ns.ior 命名服务 es.ior事件服务 ifr.ior 接口库服务 Consumer.ior
set "files=ns.ior es.ior ifr.ior Consumer.ior"

:: 遍历文件列表并删除存在的文件
for %%f in (%files%) do (
    if exist "%%f" (
        echo Deleting %%f...
        del "%%f"
        if not errorlevel 1 (
            echo Deleted %%f successfully.
        ) else (
            echo Error deleting %%f.
        )
    ) else (
        echo %%f does not exist. Skipping.
    )
)

::0) Start tao_ifr_service 启动接口库服务器并将 Messenger 接口的接口描述加载到其中
echo "==>Start tao_ifr_service"
start "tao_ifr_service" cmd /k "%TAO_ROOT%/orbsvcs/IFR_Service/tao_ifr_service -ORBdebuglevel 0 -o %PROJECT_PATH%/ifr.ior"
timeout /t 3

::1) Load Messenger.idl
echo "==>Load Messenger.idl"
start "tao_ifr" cmd /k "%ACE_ROOT%/bin/tao_ifr -ORBInitRef InterfaceRepository=file://%PROJECT_PATH%/ifr.ior Messenger.idl"
timeout /t 3


::1) Start tao_ft_naming
echo "==>Start Naming_Service"
start "tao_cosnaming" cmd /k "%TAO_ROOT%/orbsvcs/Naming_Service/tao_cosnaming -o %PROJECT_PATH%/ns.ior"
timeout /t 3


::2) Start tao_cosevent
echo "==>Start tao_cosevent"
start "tao_cosevent" cmd /k "%TAO_ROOT%/orbsvcs/CosEvent_Service/tao_cosevent -t -o %PROJECT_PATH%/es.ior -ORBInitRef NameService=file://%PROJECT_PATH%/ns.ior -ORBInitRef InterfaceRepository=file://%PROJECT_PATH%/ifr.ior"
timeout /t 3

::4) Start Consumer
echo "==>Start Consumer"
start "Consumer" cmd /k "Consumer -ORBInitRef NameService=file://%PROJECT_PATH%/ns.ior"
timeout /t 3

::5) Start Supplier 通知所有的消费者
echo "==>Start Supplier"
start "Supplier" cmd /k "Supplier -ORBInitRef NameService=file://%PROJECT_PATH%/ns.ior"

pause >nul
@echo off
